﻿using System;

namespace AladdinGameFramework
{
	/// <summary>
	/// 变量
	/// </summary>
	/// <typeparam name="T">变量类型</typeparam>
	public abstract class Variable<T> : Variable
	{
		private T m_Value;

		/// <summary>
		/// 获取变量的新实例
		/// </summary>
		protected Variable()
		{
			m_Value = default(T);
		}

		/// <summary>
		/// 初始化变量新实例
		/// </summary>
		/// <param name="value">初始值</param>
		protected Variable(T value)
		{
			m_Value = value;
		}

		/// <summary>
		/// 获取变量类型
		/// </summary>
		public override Type Type
		{
			get
			{
				return typeof(T);
			}
		}

		/// <summary>
		/// 获取或者设置变量值
		/// </summary>
		public T Value
		{
			get
			{
				return m_Value;
			}
			set
			{
				m_Value = value;
			}
		}

		/// <summary>
		/// 获取变量值
		/// </summary>
		/// <returns>变量值</returns>
		public override object GetValue()
		{
			return m_Value;
		}

		/// <summary>
		/// 重置变量值
		/// </summary>
		public override void Reset()
		{
			m_Value = default(T);
		}

		/// <summary>
		/// 获取变量字符串
		/// </summary>
		/// <returns>变量字符串</returns>
		public override string ToString()
		{
			return (m_Value != null) ? m_Value.ToString() : "<Null>";
		}
	}
}
